class Solution {
public:
    void merge(int A[], int m, int B[], int n) {
        // Start typing your C/C++ solution below
        // DO NOT write int main() function
        int index = n + m - 1;
        int i = m - 1;
        int j = n - 1;

        while (i >= 0 || j >= 0) {
            if (j < 0 || (i >= 0 && A[i] >= B[j])) {
                A[index--] = A[i];
                --i;
            } else {
                A[index--] = B[j];
                --j;
            }
        }
    }
};
